package com.ff.discounts.component.returnmaney

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.ImageView
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.unit.dp
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.QuickViewHolder
import com.ff.discounts.R
import com.ff.discounts.component.tab.home.HistoryData
import com.ff.discounts.databinding.ItemReturnGoodsBinding
import com.ff.discounts.library.log.HiLog

/**
 *
 * @author: fufang
 * @date: 2023/11/1
 */
class ReturnGoodsAdapter : BaseQuickAdapter<HistoryData, ReturnGoodsAdapter.ViewHolder>() {
    override fun onBindViewHolder(holder: ViewHolder, position: Int, data: HistoryData?) {
        holder.bindData(data!!)
        holder.itemView.setOnClickListener {
            HiLog.d(data)
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): ViewHolder {
        return ViewHolder(ItemReturnGoodsBinding.inflate(LayoutInflater.from(context), parent, false))
    }


    /**
     * VH
     */
    inner class ViewHolder(val binding: ItemReturnGoodsBinding) :
        RecyclerView.ViewHolder(binding.root) {
        /**
         * 显示数据
         */
        fun bindData(data: HistoryData) {
           binding.composeProgressIndicator.setContent {
               var progressValue by remember { mutableStateOf(0F) }
               for (i in 1..100) {
                   progressValue = i.toFloat()
               }
               progressbar(value = progressValue)
           }
        }

    }

    @Composable
    private fun progressbar(modifier: Modifier = Modifier, value: Float) {

        Canvas(modifier.padding(16.dp).width(110.dp)) {

            val canvasWidth = size.width  // 画布的宽
            val canvasHeight = size.height  // 画布的高

            drawLine(
                color = Color(0xFFFD3537),
                start = Offset(0f, 0f),
                end = Offset(canvasWidth*(value/100), 0f),
                strokeWidth = 40f ,
                cap = StrokeCap.Round
            )

        }
    }

}